﻿#pragma once

#include "VertexArray.h"

class BlockVertex
{
public:
  glm::vec3 position{0.f};
  glm::vec3 normal{0.f};
  glm::vec2 uv{0.f};

  /**
 * packed layout:
 *  00-05: Texture index x (0-63)
 *  06-11: Texture index y (0-63)
 *  12-16: Anim size (0-127) 
 *  17-18: Occlusion level (0-3)
 *  19-22: Vertex Light (0-15)
 */
  uint32_t packed{0};


public:
  BlockVertex() = default;
  BlockVertex(const glm::vec3 &position, const glm::vec2 &uv, const glm::vec3 &normal = glm::vec3(0.f))
      : position(position), uv(uv), normal(normal) {}

  void SetUv(const glm::vec2 &uv);
  void SetNormal(const glm::vec3 &normal);
  void SetTexture(uint8_t x, uint8_t y);
  void SetAnimSize(uint16_t size);
  void SetOcclusionLevel(uint8_t occlusionLevel);
  void SetVertexLight(uint8_t light);

  glm::ivec3 GetPosition() const;

  static std::vector<VertexAttribute> VertexAttributes()
  {
    return {
      VertexAttribute(3, VertexAttribute::Float),
      VertexAttribute(3, VertexAttribute::Float),
      VertexAttribute(2, VertexAttribute::Float),
      VertexAttribute(1, VertexAttribute::UInt),
    };
  }
};

//static_assert(sizeof(BlockVertex) == (sizeof(uint32_t) * 3 + sizeof(glm::vec3)), "The BlockVertex struct must not have padding");
